
#import <UIKit/UIKit.h>
#import <libxml/tree.h>

@class EventsGeoRSSImporter, NBJEvent;

// Protocol for the importer to communicate with its delegate.
@protocol EventsGeoRSSImporterDelegate <NSObject>

@optional
// Notification posted by NSManagedObjectContext when saved.
- (void)importerDidSave:(NSNotification *)saveNotification;
// Called by the importer when parsing is finished.
- (void)importerDidFinishParsingData:(EventsGeoRSSImporter *)importer;
// Called by the importer in the case of an error.
- (void)importer:(EventsGeoRSSImporter *)importer didFailWithError:(NSError *)error;

@end


@interface EventsGeoRSSImporter : NSOperation {
@private
    id <EventsGeoRSSImporterDelegate> delegate;
	
    // Reference to the libxml parser context
    xmlParserCtxtPtr context;
    NSURLConnection *rssConnection;

	// Parser state machine vars
    BOOL done;
    BOOL parsingAnEvent;
    BOOL storingCharacters;
    NSMutableData *characterBuffer;
	NBJEvent *currentEvent;
	NSDate *nbjEpochTime;
	
    NSUInteger countForCurrentBatch;
    NSAutoreleasePool *importPool;
    NSManagedObjectContext *insertionContext;
    NSPersistentStoreCoordinator *persistentStoreCoordinator;
    NSEntityDescription *eventEntityDescription;
}

@property (nonatomic, assign) id <EventsGeoRSSImporterDelegate> delegate;
@property (nonatomic, retain) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain, readonly) NSManagedObjectContext *insertionContext;
@property (nonatomic, retain, readonly) NSEntityDescription *eventEntityDescription;
@property (nonatomic, retain, readonly) NSDate *nbjEpochTime;

- (void) main;

@end
